package com.party.core.service.enterpriseservice.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.common.utils.UUIDUtils;
import com.party.core.dao.read.enterpriseservice.EpCategoryCityReadDao;
import com.party.core.dao.write.enterpriseservice.EpCategoryCityWriteDao;
import com.party.core.model.city.City;
import com.party.core.model.enterpriseservice.EpCategoryCity;
import com.party.core.service.enterpriseservice.IEpCategoryCityService;
import com.sun.istack.NotNull;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
 * @program: party
 * @description: 服务城市关系service实现
 * @author: Hua Qunhao
 * @create: 2019-01-08 16:17
 */
@Service("EpCategoryCityService")
public class EpCategoryCityService implements IEpCategoryCityService {
    @Autowired
    private EpCategoryCityReadDao epCategoryCityReadDao;

    @Autowired
    private EpCategoryCityWriteDao epCategoryCityWriteDao;


    @Override
    public String insert(EpCategoryCity epCategoryCity) {
        String uuid = UUIDUtils.generateRandomUUID();
        if (Strings.isNullOrEmpty(epCategoryCity.getId())) {
            epCategoryCity.setId(uuid);
        }
        boolean result = epCategoryCityWriteDao.insert(epCategoryCity);
        if (result) {
            return epCategoryCity.getId();
        }
        return null;
    }

    @Override
    public boolean update(EpCategoryCity epCategoryCity) {
        return epCategoryCityWriteDao.update(epCategoryCity);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return epCategoryCityWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return epCategoryCityWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {

        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return epCategoryCityWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return epCategoryCityWriteDao.batchDelete(ids);
    }

    @Override
    public EpCategoryCity get(String id) {
        return epCategoryCityReadDao.get(id);
    }

    @Override
    public List<EpCategoryCity> listPage(EpCategoryCity epCategoryCity, Page page) {
        return epCategoryCityReadDao.listPage(epCategoryCity,page);
    }

    @Override
    public List<EpCategoryCity> list(EpCategoryCity epCategoryCity) {
        return epCategoryCityReadDao.listPage(epCategoryCity,null);
    }

    @Override
    public List<EpCategoryCity> batchList(Set<String> ids, EpCategoryCity epCategoryCity, Page page) {
        if (CollectionUtils.isEmpty(ids)){
            return Collections.EMPTY_LIST;
        }
        return epCategoryCityReadDao.batchList(ids, new HashedMap(), page);
    }

    @Override
    public EpCategoryCity findByCategoryCitybyCid(EpCategoryCity EpCategoryCity) {
        return epCategoryCityReadDao.findByCategoryCitybyCid(EpCategoryCity);
    }

    @Override
    public void deleteEpCategoryCityByCid(EpCategoryCity epCategoryCity) {
        epCategoryCityWriteDao.deleteEpCategoryCityByCid(epCategoryCity);
    }

    @Override
    public List<City> queryCityListByCategoryId(String categoryId) {
        return epCategoryCityReadDao.queryCityListByCategoryId(categoryId);
    }
}
